﻿@using eLoan.Models;
@model ProspectListModel

@{
    ViewBag.Title = "Prospects";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Prospects</h2>
        <ol class="breadcrumb">
            <li>
                Masterfile
            </li>
            <li class="active">
                <strong>Prospects</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            @using (Html.BeginForm("RefreshProspectList", "Masterfile", FormMethod.Post, new { id = "saveForm" }))
            {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div>
                        <a href="@Url.Action("AddEditProspect", "Masterfile", new { @branchCode = Model.SelectedBranchCode })" class="btn btn-primary">Add a new prospect</a>
                    </div>
                    <div class="divSearch">
                        <table class="table-search">
                            <tr>
                                <td>
                                    <span>@Html.LabelFor(m => m.Branches)</span>
                                    @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "text-box single-line", @onchange = "GetAgents();" })
                                </td>
                                <td>
                                    <span>@Html.LabelFor(m => m.Agents)</span>
                                    @Html.DropDownListFor(m => m.SelectedAgentID, Model.Agents, new { @id = "ddlAgents", @class = "text-box single-line" })
                                </td>
                                <td>
                                    <span>@Html.LabelFor(m => m.SearchText)</span>
                                    @Html.TextBoxFor(m => m.SearchText, new { @id = "txtSearchText", @class = "text-box single-line", @width = "50%" })
                                </td>
                                <td style="vertical-align:bottom">
                                    <button type="submit" id="btnSearch" class="btn btn-primary btnSearch" name="command" value="Refresh">Search</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="ibox-content">
                    
                    <table class="table table-bordered table-List" >
                            <thead>
                                <tr>
                                    <th>Prospect</th>
                                    <th>Agent</th>
                                    <th>Loan Offer</th>
                                    <th>Address</th>
                                    <th>Contact Numbers</th>
                                    <th>Email Addresses</th>
                                    <th>Date Added</th>
                                    <th>Is Active</th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.PropsectList.Count(); i++)
                                {
                                <tr>
                                    <td>@Html.DisplayFor(m => Model.PropsectList[i].ProspectName)</td>
                                    <td>@Html.DisplayFor(m => Model.PropsectList[i].AgentName)</td>
                                    <td>@Html.ValueFor(m => Model.PropsectList[i].LoanOffer, "{0:#,###,##0.00}")</td>
                                    <td>@Html.DisplayFor(m => Model.PropsectList[i].Address)</td>
                                    <td>@Html.DisplayFor(m => Model.PropsectList[i].ContactNumbers)</td>
                                    <td>@Html.DisplayFor(m => Model.PropsectList[i].EmailAddresses)</td>
                                    <td>@Html.ValueFor(m => Model.PropsectList[i].DateAdded, "{0:yyyy/MM/dd}")</td>
                                    <td style="text-align:center">@Html.DisplayFor(m => Model.PropsectList[i].IsActive)</td>
                                    <td>@Html.ActionLink("Edit", "AddEditProspect", "Masterfile", null, null, null, new { branchCode = Model.SelectedBranchCode, id = Model.PropsectList[i].ID }, null)</td>
                                    <td>@Html.ActionLink("Delete", "DeleteProspect", "Masterfile", null, null, null, new { branchCode = Model.SelectedBranchCode, id = Model.PropsectList[i].ID }, null)</td>
                                </tr> 
                                }
                            </tbody>
                        </table>
                    
                </div>
            </div>
            }
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    @Styles.Render("~/plugins/dataPickerStyles")
<style>
    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
    }

    .table-search {
        width: 70%;
        border: none;
    }

    .table-search td {
        margin: 10px 10px 10px 10px;
        padding: 10px 10px 10px 10px;
        vertical-align: bottom;
    }

    .table-search td .btnSearch {
        margin-bottom: 0px;
    }

    .table-search td span {
        margin-left: 5px;
    }

    .scrollable {
        height: 400px;
        overflow-y: scroll;
        border: solid 1px #EBEBEB;
    }
</style>

}

@section Scripts {
@Scripts.Render("~/plugins/dataPicker")
@Scripts.Render("~/plugins/dataTables")
    <script type="text/javascript">

        $(document).ready(function () {

            $('.table-List').dataTable({
                ordering: true,
                searching: false,
                paging: false,
                scrollY: 400,
                scrollX: true
            });

            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    Refresh();
                    return false;
                }
            });
        });

        function Refresh() {
            document.getElementById('btnSearch').click();
        }

        function GetAgents()
        {
            var val = $('#ddlBranches').val();
            var subItems = "";
        
            $.getJSON("@Url.Action("GetAgents","Loan")", { branchCode: val },
        function (data) {
            subItems += "<option value='0'>All</option>"
            $.each(data, function (index, item) {

                subItems += "<option value='" + $.trim(item.Value) + "'>" + $.trim(item.Text) + "</option>"

            });
                
            $("#ddlAgents").html(subItems)
        });
 
        }

    </script>

}
